﻿do
	IGAS:NewAddon("IGAS_Studio")

    ------------------------------------------------------
	-- AdvanceForm
	------------------------------------------------------
	local _WidgetName = "AdvanceForm"
    local _Base = "Form"

    -- Scripts
    local function spL2D_OnEnter(self)
		self.HighLight.Visible = true
	end

	local function spL2D_OnLeave(self)
		self.HighLight.Visible = false
	end

	local function spL2D_OnMouseDown(self)
		self.Parent.List:StartSizing("RIGHT")
	end

	local function spL2D_OnMouseUp(self)
		self.Parent.List:StopMovingOrSizing()
		self.Parent.List:SetPoint("TOPLEFT", self.Parent, "TOPLEFT", 4, -26)
		self.Parent.List:SetPoint("BOTTOMLEFT", self.Parent, "BOTTOMLEFT", 4, 56)
	end
	
	local function btnAdd_OnClick(self)
		self.Parent:Fire("OnAddClick")
	end
	
	local function btnRemove_OnClick(self)
		self.Parent:Fire("OnRemoveClick")
	end
	
	local function btnCancel_OnClick(self)
		self.Parent.Visible = false
	end
	
	local function btnOkay_OnClick(self)
		self.Parent:Fire("OnOkayClick")
	end
	
	local function btnUp_OnClick(self)
		self.Parent:Fire("OnUpClick")
	end
	
	local function btnDown_OnClick(self)
		self.Parent:Fire("OnDownClick")
	end

	-- ScriptType
	local _ScriptType = {
		["OnAddClick"] = true,
		["OnRemoveClick"] = true,
		["OnOkayClick"] = true,
		["OnUpClick"] = true,
		["OnDownClick"] = true,
	}

	-- Function
	local _Function = {
    }

	-- Property
	local _Property = {
    }

    -- New
    local function _New(name, parent)
		local form = CreateFrame(_Base, name, parent)
		form.Width = 600
		form.Height = 400
		form.Visible = false
		form.FrameStrata = "FULLSCREEN_DIALOG"

		local lstItem = CreateFrame("List", "List", form)
		lstItem:SetPoint("TOPLEFT", form, "TOPLEFT", 4, -26)
		lstItem:SetPoint("BOTTOMLEFT", form, "BOTTOMLEFT", 4, 56)
		lstItem:SetMinResize(50, 10)
		lstItem:SetMaxResize(300, 2000)
		lstItem.Width = 150
		lstItem.Resizable = true

		local dgValue = CreateFrame("DataGrid", "DataGrid", form)
		dgValue:SetPoint("TOPLEFT", lstItem, "TOPRIGHT", 4, 0)
		dgValue:SetPoint("BOTTOMRIGHT", form, "BOTTOMRIGHT", -4, 56)
		dgValue.ColumnCount = 2
		dgValue.Columns(1).CellType = "Label"
		dgValue.Columns(1).Text = L["Field"]
		dgValue.Columns(2).Text = L["Value"]
		dgValue.Columns(1).ColumnWidth = 40

		-- Seperates
		local spLD = CreateFrame("Frame", "spL2D", form)
		spLD.MouseEnabled = true
		spLD:SetPoint("TOPLEFT", lstItem, "TOPRIGHT")
		spLD:SetPoint("BOTTOMLEFT", lstItem, "BOTTOMRIGHT")
		spLD:SetPoint("TOPRIGHT", dgValue, "TOPLEFT")
		spLD:SetPoint("BOTTOMRIGHT", dgValue, "BOTTOMLEFT")
		local highLight = CreateFrame("Texture", "HighLight", spLD, "BACKGROUND")
		highLight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
		highLight:SetBlendMode("ADD")
		highLight:SetAllPoints(spLD)
		highLight.Visible = false
		
		spLD.OnEnter = spL2D_OnEnter
		spLD.OnLeave = spL2D_OnLeave
		spLD.OnMouseDown = spL2D_OnMouseDown
		spLD.OnMouseUp = spL2D_OnMouseUp

		-- Add Button
		local btnAdd = CreateFrame("NormalButton", "btnAdd", form)
		btnAdd:SetPoint("BOTTOMLEFT", form, "BOTTOMLEFT", 4, 24)
		btnAdd.Height = 24
		btnAdd.Width = 100
		btnAdd.Style = "NORMAL"
		btnAdd.Text = L["Add"]
		btnAdd.OnClick = btnAdd_OnClick
		
		-- Remove Button
		local btnRemove = CreateFrame("NormalButton", "btnRemove", form)
		btnRemove:SetPoint("LEFT", btnAdd, "RIGHT")
		btnRemove.Height = 24
		btnRemove.Width = 100
		btnRemove.Style = "NORMAL"
		btnRemove.Text = L["Remove"]
		btnRemove.OnClick = btnRemove_OnClick
		
		-- Up Button
		local btnUp = CreateFrame("NormalButton", "btnUp", form)
		btnUp:SetPoint("LEFT", btnRemove, "RIGHT")
		btnUp.Height = 24
		btnUp.Width = 100
		btnUp.Style = "NORMAL"
		btnUp.Text = L["Up"]
		btnUp.Enabled = false
		btnUp.OnClick = btnUp_OnClick
		
		-- Down Button
		local btnDown = CreateFrame("NormalButton", "btnDown", form)
		btnDown:SetPoint("LEFT", btnUp, "RIGHT")
		btnDown.Height = 24
		btnDown.Width = 100
		btnDown.Style = "NORMAL"
		btnDown.Text = L["Down"]
		btnDown.Enabled = false
		btnDown.OnClick = btnDown_OnClick
		
		
		-- Cancel button
		local btnCancel = CreateFrame("NormalButton", "btnCancel", form)
		btnCancel:SetPoint("BOTTOMRIGHT", form, "BOTTOMRIGHT", -4, 24)
		btnCancel.Height = 24
		btnCancel.Width = 100
		btnCancel.Style = "NORMAL"
		btnCancel.Text = L["Cancel"]
		btnCancel.OnClick = btnCancel_OnClick
		
		-- Okay Button
		local btnOkay = CreateFrame("NormalButton", "btnOkay", form)
		btnOkay:SetPoint("RIGHT", btnCancel, "LEFT")
		btnOkay.Height = 24
		btnOkay.Width = 100
		btnOkay.Style = "NORMAL"
		btnOkay.Text = L["Okay"]
		btnOkay.OnClick = btnOkay_OnClick
		
        return form
    end

    local _WidgetInfo = {
        ["WidgetName"] = _WidgetName,
        ["Base"] = _Base,
        ["Function"] = _Function,
        ["Property"] = _Property,
        ["ScriptType"] = _ScriptType,
        ["New"] = _New,
		-- Special Item
    }

    Widget[_WidgetName] = IGAS:NewWidget(_WidgetInfo)
end